﻿package com.dbm.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.dbm.model.ConnPoolFactory;

public class CtlPublicDao {
	
	
	/**
	 * 将发送失败的http请求写入数据库
	 * @param param
	 * @return
	 * @throws Exception
	 */
	public synchronized boolean addCtlErrorHttpPost(String param) throws Exception{
		boolean flag = false;
		String sql = "INSERT INTO ERRORHTTPPOST VALUES (SEQERRORHTTPPOST.NEXTVAL,?,'N')";
		Connection ctlconn = ConnPoolFactory.getCtlConnection();
		PreparedStatement ctlstat = ctlconn.prepareStatement(sql);
		ctlstat.setString(1, param);
		if(ctlstat.executeUpdate()==1){
			flag = true;
		}
		ctlstat.close();
		ctlconn.close();
		return flag;
	}
	
	/**
	 * 获取序列nextval
	 * 
	 * @param seq
	 * @return
	 * @throws Exception
	 */
	public synchronized String getEntryOrderIdBySeq(String seq)
			throws Exception {
		System.out.println("即将调用"+seq);
		String result = "";
		Connection ctlconn = ConnPoolFactory.getCtlConnection();
		System.out.println("获取到数据库连接："+ctlconn);
		// CTL数据库处理
		String getSeqNextValSql = "select " + seq + ".NEXTVAL seqval from dual";
		PreparedStatement ctlStat = ctlconn.prepareStatement(getSeqNextValSql);
		ResultSet rs = ctlStat.executeQuery();
		if (rs.next()) {
			result = rs.getString("seqval");
		}
		rs.close();
		ctlStat.close();
		ctlconn.close();
		System.out.println("调用"+seq+"结果：\t"+result);
		return result;
	}

}
